package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 查询通用设置
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }
    /**
     * 设置陌生人问题
     * 参数:token,JSON
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 通知设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        //获取参数
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    /*
    * 黑名单管理
    * 查询黑名单
    * */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") int page ,@RequestParam(defaultValue = "10") int size){
      PageResult pr= settingsService.blacklist(page,size);
      return ResponseEntity.ok(pr);
    }
    /*
    * 删除黑名单中的用户
    * */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteblacklist(@PathVariable("uid") Long blackUserId){
        settingsService.deleteblacklist(blackUserId);
        return ResponseEntity.ok(null);

    }
}